package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GennericDemo {
    public static void main(String[] args) {
        Collection<point> c=new ArrayList<>();
        c.add(new point(1,2));
        c.add(new point(2,3));
        c.add(new point(4,6));
        c.add(new point(7,8));

        Iterator<point> it =c.iterator();
        while (it.hasNext()){
            point p =it.next();
            System.out.println(p);
        }
        for (point p:c){
            System.out.println(p);
        }
//        Collection<String> c= new ArrayList<>();
//        c.add("one");
//        c.add("two");
//        c.add("three");
//        c.add("four");
//        c.add("five");
//        //迭代器所指对的泛型应当与其遍历的集合的泛型一致
//        Iterator<String> it=c.iterator();
//        while (it.hasNext()){
//            String str =it.next();
//            System.out.println(str);
//        }
//        for (String str:c){
//            System.out.println(str);
//        }
    }
}
